﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MBaoYangListEasyUI.aspx.cs" Inherits="IHISCETeim.Web.MachineSys.MarketModel.MBaoYangListEasyUI" %>
<%--保养件赠送管控表--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../EasyUI/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="../EasyUI/themes/icon.css" />
	<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>   
	<script type="text/javascript" src="../EasyUI/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../EasyUI/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../EasyUI/easyui-formatter_20140718.js"></script>
   
    <script type="text/javascript">
        ///自适应宽高
       $(window).resize(function(){		    
             $("#tab_list").datagrid({
                    width: '100%',
                    height: $(parent.document).find(".tabsPageContent").height() - 11 > 0 ? $(parent.document).find(".tabsPageContent").height() - 11 : 500,
             }); 
	    });
        //权限处理
        var $powers={
            "r查看":<%=HasPowerEasyUI(IHISCETeim.Web.Permission.查看) %>,
            "r新增":<%=HasPowerEasyUI(IHISCETeim.Web.Permission.新增) %>,
            "r修改":<%=HasPowerEasyUI(IHISCETeim.Web.Permission.修改) %>,
            "r删除":<%=HasPowerEasyUI(IHISCETeim.Web.Permission.删除) %>,
            "r导出":<%=HasPowerEasyUI(IHISCETeim.Web.Permission.导出) %>
        };

        $(document).ready(function () {
            var $tab_toolbar=$("#tab_toolbar");
            $tab_toolbar.find("a").each(function(){
                var $per=$(this).attr("Permission");
                var pt= $powers[$per]==undefined || null?true:$powers[$per];
                $(this).linkbutton(pt?'enable': 'disable');
            })      
             $("#btnSave").linkbutton('disable');
            //导出
            $('#MBaoYangListEasyUIExportDialog').dialog({
				buttons:[{
					text:'确定导出',
					iconCls:'icon-ok',
                    plain:"true" ,
					handler:function(){
						var href = "<%= ExportExcelWebUrl%>/MarketModel/MBaoYangList.aspx?"+ jQuery.param($("#MBaoYangListEasyUIExportDialog").serializeJSON());;
                        top.window.open(href, "");
                        $('#MBaoYangListEasyUIExportDialog').dialog('close');
					}
				},{
					text:'关闭',
                    plain:"true" ,
					handler:function(){
						$('#MBaoYangListEasyUIExportDialog').dialog('close');
					}
				}]
			});
            $('#MBaoYangListEasyUIExportDialog').dialog('close');
                        
            //加载数据
            InitGird();           
        })
        //加载列表数据
        var editIndex=undefined;
        function InitGird() {
            $('#tab_list').datagrid({               
                url: location.href, //请求数据的页面
                sortName: 'id', //排序字段
                sortOrder: 'desc', //排序类型
                idField: 'id', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度    
                height: $(parent.document).find(".tabsPageContent").height() - 11 > 0 ? $(parent.document).find(".tabsPageContent").height() - 11 : 500,
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                singleSelect: true, //是否只能选中一条
                remoteSort: true, //定义是否从服务器给数据排序
                frozenColumns: [[//冻结的列，不会随横向滚动轴移动
                    { title: '申请人', field: 'SQR', width: 60, align:'left',sortable:true },
                    {title:'经销商',field:'JXS',width: 80,sortable:true},
                    {title: '用户名', field: 'YHM', width: 80 ,sortable: true}                    
				]],
                columns: [[         
                    {title: '机型', field: 'JX', width: 60, align:'left', sortable: true},
                    {title: '机号', field: 'JH', width: 70, align:'left', sortable: true}, 
                    { title: '赠送原因', field: 'ZSYY', width: 90, sortable: true, sortable: true},                  
                    { title: '展会/合同号', field: 'BB_ZHHTH', width: 110 , sortable: true},
                    { title: '配件种类', field: 'PJZL', width: 100, sortable: true },
                    { title: '备注',field: 'BZ', width:120, sortable: true},
                    { title: '数量',field: 'SL', width:60, sortable: true},
                    { title: '申请时间',field: 'SQSJ', width:70, sortable: true, formatter:formatterdate},     
                    { title: '执行时间',field: 'ZXSJ', width:70, sortable: true},    
                    { title: '出库时间',field: 'CKSJ', width:100,editor:'datebox', sortable: true},   
                    { title: '出库单号',field: 'CKDH', width:100,editor:'text', sortable: true}, 
                    { title: '凭证号',field: 'PZH', width:100,editor:'text', sortable: true} 
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: <%=numPerPage %>, //默认一页数据条数
                pageList:<%=SetnumPerPage() %>,
                rownumbers: true, //行号
                showFooter: false,
                onClickRow: function (rowIndex) {
                    if(<%=HasPowerEasyUI(IHISCETeim.Web.Permission.保养件赠送_配件) %>==false || <%=HasPowerEasyUI(IHISCETeim.Web.Permission.保养件赠送_配件) %>==undefined )
                    {
                        return false;
                    }
                    onClickRow(rowIndex);
		        },
                onAfterEdit:function(rowIndex, rowData, changes){
                    //onSaveClick();
                }
            });

        }       
       
        /*每行的操作处理*/
        function endEditing(){
            if (editIndex == undefined){return true}
            if ($('#tab_list').datagrid('validateRow', editIndex)){              
                $('#tab_list').datagrid('endEdit', editIndex);
                editIndex = undefined;
                return true;
            } else {
                return false;
            }
        }
        function onClickRow(index){
            if (editIndex != index){
                if (endEditing()){
                    $('#tab_list').datagrid('selectRow', index)
                            .datagrid('beginEdit', index);
                    editIndex = index;
                   /// setTimeout(function(){
                        $("#btnSave").linkbutton('enable');
                   // },1000);
                    
                } else {
                    
                    $('#tab_list').datagrid('selectRow', editIndex);
                }
            }
        }      
        
        function onSaveClick(){
            
            var row = $('#tab_list').datagrid('getSelected');           
            var ID = row.id;
           // alert(editIndex);
           // alert(ID);
            var ed = $('#tab_list').datagrid('getEditor', {index:editIndex,field:'CKDH'});
            var CKDH = $(ed.target).val();
            //alert(CKDH);

            ed = $('#tab_list').datagrid('getEditor', {index:editIndex,field:'CKSJ'});
            var CKSJ = $(ed.target).val();

            ed = $('#tab_list').datagrid('getEditor', {index:editIndex,field:'PZH'});
            var PZH = $(ed.target).val();

            var $data={};
            $data["id"]=ID;                  
            $data["CKSJ"]=CKSJ;//==undefined?rowData.CKSJ:changes.CKSJ;
            $data["CKDH"]=CKDH;//==undefined?rowData.CKDH:changes.CKDH;
            $data["PZH"]=PZH;//==undefined?rowData.PZH:changes.PZH;
            $data["action"]="editrow";    

             $.ajax({
                    type: 'post',
                    url: location.href,
                    data:$data,
                    async: true,
                    cache: false,
                    dataType: "text",
                    success: function (json) {
                        try {
                            if (json!="") {
                                alert(json);
                            }
                        }
                        catch (e) {

                        }
                    }
             });
            $("#btnSave").linkbutton('disable');
            if (endEditing()){
                $('#tab_list').datagrid('acceptChanges');
            }
           editIndex = undefined;

           $('#tab_list').datagrid('unselectAll')//取消选中,不然会直接选中上次的数据
        }
        
       
        
    </script>
    <script>
        //操作功能JS

        //打开高级查找窗口
        function onAdjSearch() {
            $("#tab_search").dialog("open");
            $("#search-buttons").find("#btn_search").one("click", function () {
                var query = $("#tab_search").serializeJSON(); // GetInputData("tab_search", "query");
                query.action = "query";
                $('#tab_list').datagrid("options").queryParams = query;
                $('#tab_list').datagrid('load');
                $("#tab_search").dialog("close");

                editIndex = undefined;
                return false;

            });
        }
        //添加
        function onAddClick() {

            var rel = "MBaoYangAdd";
            var url = "MarketModel/MBaoYangAdd.aspx";
            var title = "添加保养件赠送申请记录";
            var options = { width: 850, height: 500, max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };
            top.$.pdialog.open(url, rel, title, options);
            //top.navTab.openTab(rel, url, { title: title, fresh: true, external: false });
            return false;
        }

        //修改，通过工具栏
        function onEditClick() {

            var row = $('#tab_list').datagrid('getSelected')
            if (row == null) {
                $.messager.alert('提示', '请先选择要修改的记录');
                return false;
            }           

            var rel = "MBaoYangEdit";
            var url = "MarketModel/MBaoYangEdit.aspx?ID=" + row.id;
            var title = "修改保养件赠送申请记录";
            var options = { width: 850, height: 500, max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };
            top.$.pdialog.open(url, rel, title, options);
            //top.navTab.openTab(rel, url, { title: title, fresh: true, external: false });
            $('#tab_list').datagrid('unselectAll')//取消选中,不然会直接选中上次的数据
            return false;
        }
        //删除
        function onDelClick() {

            var row = $('#tab_list').datagrid('getSelected')
            if (row == null) {
                $.messager.alert('提示', '请先选择要删除的记录');
                return false;
            }
            var ID = row.id;
            $.messager.confirm('提示', '您确认要删除此记录吗？', function (r) {
                if (r) {
                   // var FTradeID = row.FTradeID;
                    var url = "sysAjaxDone.ashx?ajaxmethod=deletembaoyang&ID=" + ID;
                    top.ajaxTodo(url, "");
                    $("#tab_list").datagrid("load");

                }
            });

            $('#tab_list').datagrid('unselectAll')//取消选中,不然会直接选中上次的数据
            return false;
        }

        //选择保养件申请日期
        function onExportClick() {
            $('#MBaoYangListEasyUIExportDialog').dialog('open');
        }

    </script>
</head>
<body style="margin:2px;" >
    <div id="tab_list"></div>
    <div id="tab_toolbar" style="padding:2px;">
       <a href="#" title="高级查找" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="return　onAdjSearch(this);" Permission="">查找</a>
       <a href="#" title="添加记录" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="return 　onAddClick()" Permission="r新增">新增</a>
       <a href="#" title="修改信息" class="easyui-linkbutton" iconcls="icon-save" plain="true" onclick="return　onEditClick();" Permission="r修改">修改</a>
       <a href="#" title="删除" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="return　onDelClick();" Permission="r删除">删除</a> 
       <a href="#" title="导出" class="easyui-linkbutton" iconcls="icon-tip" plain="true" onclick="return　onExportClick();"  Permission="r导出">导出</a>

       <a href="#" title="保存" id="btnSave" class="easyui-linkbutton" iconcls="icon-save" plain="true" onclick="return　onSaveClick();" Permission="">保存</a>
    </div>   

    <div id="MBaoYangListEasyUIExportDialog" icon="icon-save" title="选择保养件申请日期"  style="padding:5px;width:350px;height:180px;" modal="true" closed="true">
		<p>请选择要导出的保养件申请日期区间：</p>
		<p>
            从<input name="DateFrom" class="easyui-datebox" type="text" value="" />
            到<input name="DateTo" type="text" class="easyui-datebox" value="" />
        </p>		
	</div>

    <div id="tab_search" title="查询条件" style=" height:250px; width:500px;" class="easyui-dialog" modal="true" closed="true" buttons="#search-buttons">
        <table class="table_search" width="100%" style=" line-height:21px;">
            <tr>
                <td>经销商:</td>
                <td colspan="3"><input  name="JXS"  /></td>
            </tr>
            <tr>
                <td>机号:</td>
                <td><input  name="JH"  /></td>
                <td>出库单号:</td>
                <td><input  name="CKDH"  /></td>
            </tr>
             <tr>
                <td>凭证号:</td>
                <td><input  name="PZH"  colspan="3"/></td>
            </tr>
            <tr>
                <td>
                    申请时间：
                </td>
                <td  colspan="3">                    
                    从<input name="SQSJFrom" class="easyui-datebox" type="text" value="" />
                    到<input name="SQSJTo" type="text" class="easyui-datebox" value="" />
                </td>
            </tr>
        </table>
        <div id="search-buttons" style=" ">
            <a id="btn_search" href="javascript:;" class="easyui-linkbutton" iconcls="icon-search" plain="true">提交</a> 
            <a href="javascript:;" class="easyui-linkbutton" onclick="$('#tab_search').dialog('close');return false;" iconcls="icon-cancel" plain="true">取消</a>
        </div>
    </div>

   
</body>
</html>